package peerToPeerFacebook.proj;

/**
 * Provides static helper methods for argument validations
 */
public final class ArgumentValidator 
{
	/**
	 * Checks if argument is greater than min
	 * @param argName Name of the argument
	 * @param arg Argument
	 * @param min Value to compare against
	 */
	public static void IsGreaterThan(String argName, int arg, int min)
			throws IllegalArgumentException
	{
		if (arg <= min)
		{
			throw new IllegalArgumentException(String.format("Argument '%s' with value %d was less than or equal to %d!",
															 argName,
															 arg,
															 min));
		}
	}
	
	/**
	 * Checks if argument is greater than or equal to min
	 * @param argName Name of the argument
	 * @param arg Argument
	 * @param min Value to compare against
	 */
	public static void IsGreaterThanOrEqualTo(String argName, int arg, int min)
			throws IllegalArgumentException
	{
		if (arg < min)
		{
			throw new IllegalArgumentException(String.format("Argument '%s' with value %d was less than %d!",
															 argName,
															 arg,
															 min));
		}
	}
	
	/**
	 * Checks if argument is less than max
	 * @param argName Name of the argument
	 * @param arg Argument
	 * @param max Value to compare against
	 */	
	public static void IsLessThan(String argName, int arg, int max)
			throws IllegalArgumentException
	{
		if (arg >= max)
		{
			throw new IllegalArgumentException(String.format("Argument '%s' with value %d was greater than or equal to %d!",
															 argName,
															 arg,
															 max));
		}
	}	

	/**
	 * Checks if argument is less than or equal to max
	 * @param argName Name of the argument
	 * @param arg Argument
	 * @param max Value to compare against 
	 */	
	public static void IsLessThanOrEqualTo(String argName, int arg, int max)
			throws IllegalArgumentException
	{
		if (arg > max)
		{
			throw new IllegalArgumentException(String.format("Argument '%s' with value %d was greater than %d!",
															 argName,
															 arg,
															 max));
		}
	}		

	/**
	 * Checks if argument is null
	 * @param argName Name of the argument
	 * @param arg Argument 
	 */	
	public static void IsNotNull(String argName, Object obj)
		throws IllegalArgumentException
	{
		if (obj == null)
		{
			throw new IllegalArgumentException(String.format("Argument '%s' was null!", argName));
		}
	}
	
	/**
	 * Checks if given string is null or empty
	 * @param argName Name of the argument
	 * @param arg String argument 
	 */	
	public static void IsNotNullOrEmpty(String argName, String arg)
			throws IllegalArgumentException
		{
			if (arg == null)
			{
				throw new IllegalArgumentException(String.format("Argument '%s' was null!", argName));
			}
			else if (arg.length() == 0)
			{
				throw new IllegalArgumentException(String.format("Argument '%s' was empty!", argName));
			}
		}
}
